appCtrl.controller('DistrictCtrl', function($scope, $state, $rootScope, $ionicLoading, $ionicHistory, RegionService, UtilsService, UtilsService) {
  RegionService.get().$promise.then(function(response) {
    if (UtilsService.isResponseOk(response)) {
      $scope.regions = response.data.regions;

      // if($scope.regions.length > 0){
      //   RegionService.getDistrictByArea({region: $scope.regions[0]}).$promise.then(function (response) {
      //     if(response.code == 200){
      //       $scope.districts[$scope.regions.get(0)] = response.data.districts;
      //     }
      //   });
      // }
    }
  });
  $scope.districts = {};
  $scope.showdist = [];
  $scope.selectRegion = function(region) {

    RegionService.getDistrictByArea({
      region: region
    }).$promise.then(function(response) {
      if (UtilsService.isResponseOk(response)) {
        $scope.selctRegion = region;
        $scope.showdist = response.data.districts;
      }
    });
  }


  $scope.selectDist = function(dist) {
    console.log(angular.toJson(dist))
    UtilsService.setDist(dist)
    $rootScope.dist = dist
    $state.go('dash.home', {update: true}, {reload: true})
  }

});
